﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace CC.Yacht.Windows.Forms
{
    public partial class DieLabel : UserControl
    {
        #region Constructor
        public DieLabel()
        {
            InitializeComponent();
            AutomaticText = true;
        }
        #endregion

        #region Private Fields
        private DieFace _Face = DieFace.Six;
        #endregion

        #region Public Properties
        public bool AutomaticText { get; set; }

        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = value;
                _DieControl.BackColor = value;
                _LabelMain.BackColor = value;
            }
        }

        public DieFace Face
        {
            get { return _Face; }
            set { SetFace(value); }
        }

        [Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public override string Text
        {
            get { return _LabelMain.Text; }
            set { _LabelMain.Text = value; }
        }

        [Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public ContentAlignment TextAlign
        {
            get { return _LabelMain.TextAlign; }
            set { _LabelMain.TextAlign = value; }
        }
        #endregion

        #region Private Methods
        private void CommonControl_Click(object sender, EventArgs e)
        {
            base.OnClick(e);
        }

        private void CommonControl_MouseEnter(object sender, EventArgs e)
        {
            base.OnMouseEnter(e);
        }

        private void CommonControl_MouseLeave(object sender, EventArgs e)
        {
            base.OnMouseLeave(e);
        }
        
        private void SetFace(DieFace value)
        {
            _Face = value;
            _DieControl.Face = value;

            if (AutomaticText)
            {
                _LabelMain.Text = value + ((value == DieFace.Six) ? "es" : "s");
            }
        }
        #endregion
    }
}
